from selenium.webdriver.common.by import By
from common.utils import Driver
from common.utils import ScreenShot

class BlogIndex:
    def __init__(self):
        Driver.implicitly_wait(10)

    # 检查页面元素
    def check_ele(self):
        # 头像、用户名、github地址、发布的文章数量
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[1]/div/img")
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[1]/div/h3")
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[1]/div/a")
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[1]/div/div[2]")
        # 博客列表信息：标题、发布时间、概要内容、”查看全文“按钮链接
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[1]/div[1]")
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[1]/div[2]")
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[1]/div[3]")
        Driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[1]/a").click()
        ScreenShot()
        assert "博客详情页" == Driver.title

    # 检查顶部菜单功能：主页、写博客、注销
    def check_menu(self):
        Driver.find_element(By.XPATH, "/html/body/div[1]/a[1]").click()
        ScreenShot()
        assert "博客列表页" == Driver.title
        Driver.find_element(By.XPATH, "/html/body/div[1]/a[2]").click()
        ScreenShot()
        assert "博客编辑页" == Driver.title
        Driver.find_element(By.XPATH, "/html/body/div[1]/a[3]").click()
        ScreenShot()
        assert "博客登陆页" == Driver.title